﻿Public Class FrmRepair
    Private x_repair As X_Repair
    Private x_repair_old As X_Repair

    Private _parentObj As PO
    Private _parentForm As SuperForm

    Public Sub New(ByVal xrepair As X_Repair, ByVal parentObj As PO, ByVal parentForm As SuperForm)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        Me._parentObj = parentObj
        Me._parentForm = parentForm

        Me.x_repair = xrepair
        If (Not Me._parentObj Is Nothing) Then
            Me.x_repair.setValue(I_Repair.ColumnName_MaTS, Me._parentObj.getValue(I_TSCD.ColumnName_MaSO))
            Me.x_repair.setValue(I_Repair.ColumnName_parentID, Me._parentObj.getValue(I_TSCD.ColumnName_id))
            Me.x_repair.setValue(I_Repair.ColumnName_FAType, Me._parentObj.getValue(I_TSCD.ColumnName_FAType))
            Me.x_repair.setValue(I_Repair.ColumnName_Status, CONSTANT.STATUS._DRAFTS)
        End If

        Me.x_repair_old = Me.x_repair
        ini()
    End Sub

    Public Function ini() As Boolean

        Me.txtDaiDienDVSuaChua.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_DaiDienDVSuaChua)
        Me.txtDaiDienDVTSCD.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_DaiDienDVTS)
        Me.txtBPSuaChua.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_BPSuaChua)
        Me.txtNDSuaChua.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_NDSuaChua)
        Me.txtGiaDuToan.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_GiaDuToan)
        Me.txtChiPhiThucTe.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_ChiPhiThucTe)
        Me.dtpThoiGian.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_ThoiGian)
        Me.txtKQKiemTra.Text = Me.x_repair_old.getValue(I_Repair.ColumnName_KQKiemTra)

    End Function


    Private Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        ini()
    End Sub


    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub



    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Me.x_repair.setValue(I_Repair.ColumnName_DaiDienDVSuaChua, Me.txtDaiDienDVSuaChua.Text)
        Me.x_repair.setValue(I_Repair.ColumnName_DaiDienDVTS, Me.txtDaiDienDVTSCD.Text)
        Me.x_repair.setValue(I_Repair.ColumnName_BPSuaChua, Me.txtBPSuaChua.Text)
        Me.x_repair.setValue(I_Repair.ColumnName_NDSuaChua, Me.txtNDSuaChua.Text)
        Me.x_repair.setValue(I_Repair.ColumnName_GiaDuToan, Me.txtGiaDuToan.Text)
        Me.x_repair.setValue(I_Repair.ColumnName_ChiPhiThucTe, Me.txtChiPhiThucTe.Text)
        Me.x_repair.setValue(I_Repair.ColumnName_ThoiGian, Me.dtpThoiGian.Text)
        Me.x_repair.setValue(I_Repair.ColumnName_KQKiemTra, Me.txtKQKiemTra.Text)

        Me.x_repair.save(True)

        Me._parentForm.loadRepair()
        Me._parentForm.specifyCorrespondingInventory()
        Me.Close()

    End Sub
End Class